const Router = require('@koa/router');
const multer = require('@koa/multer') 
const mysql = require('../config/mysqlPool')
// const upload = require('../utils/upload')
const upload = multer({ dest: 'uploads/'})

const router = new Router({ 
  prefix: '/api/upload' 
});

router.post('/', upload.single('avatar'), ctx => {
  console.log('ctx.request.file', ctx.request.file);
  console.log('ctx.file', ctx.file);
  console.log('ctx.request.body', ctx.request.body);
  ctx.body = 'done';
})

router.get('/test', async(ctx, next) => {
  let data = await mysql.query('select * from user')
  ctx.body = {
    data: data[0]
  }
})

module.exports = router;